package cn.bellychang.leetcode.question242;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author ChangLiang
 * @date 2021/3/16
 */
public class ContainSolution {

    /**
     * anagram 异位词的意思是每个单词的对应字母的个数是相等的
     * @param s
     * @param t
     * @return
     */
    public boolean isAnagram(String s, String t) {

        for (int i = 0; i <= s.length(); i++) {

            for (int j = i; j <= s.length(); j++) {
                String temp1 = s.substring(i, j);
                String temp2 = s.substring(j);
                if (temp1.equals(t) || temp2.equals(t)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Test
    @DisplayName("test")
    public void test(){
        String s = "anagram";
        String t = "nagram";
        assertThat(new ContainSolution().isAnagram(s, t)).isTrue();
    }

    @Test
    @DisplayName("test")
    public void test2(){
        String s = "anagram";
        String t = "gram";
        assertThat(new ContainSolution().isAnagram(s, t)).isTrue();
    }

    @Test
    @DisplayName("test")
    public void test3(){
        String s = "anagram";
        String t = "nag";
        assertThat(new ContainSolution().isAnagram(s, t)).isTrue();
    }

    @Test
    @DisplayName("test")
    public void test4(){
        String s = "anagram";
        String t = "cba";
        assertThat(new ContainSolution().isAnagram(s, t)).isFalse();
    }
}
